import QtQuick
import Qt5Compat.GraphicalEffects
import Fk
import Fk.Components.GameCommon as Game

Game.BasicItem {
  id: root

  // 基础属性（与正式版 Minion 对齐，便于替换）

  property string name
  property string description
  property int mana
  property int hp
  property int atk
  // 可选：占位立绘图片
  property url portraitSource

  // 适合列表或栅格展示的默认尺寸（可由父容器缩放）
  width: 110
  height: 160

  // 卡片背景
  Rectangle {
    id: card
    anchors.fill: parent
    radius: 6
    color: "#f7f3e8"
    border.color: "#7a5b3a"
    border.width: 2
  }

  Column {
    id: content
    anchors.fill: parent
    anchors.margins: 6
    spacing: 4

    // 顶部：法力
    Item {
      width: parent.width
      height: 18

      Rectangle {
        width: 18
        height: 18
        radius: 6
        color: "#2b6cb0"
        anchors.left: parent.left
        anchors.verticalCenter: parent.verticalCenter

        Text {
          anchors.centerIn: parent
          text: (root.mana === undefined || root.mana === null) ? 0 : root.mana
          color: "white"
          font.pixelSize: 20
          font.bold: true
        }
      }
    }

    // 占位立绘区域（可显示简图或留空）
    Rectangle {
      id: portraitArea
      width: parent.width
      height: 35
      radius: 8
      color: "#dddddd"
      border.color: "#bbbbbb"

      Image {
        anchors.fill: parent
        anchors.margins: 2
        source: root.portraitSource
        fillMode: Image.PreserveAspectCrop
        visible: source && source.toString().length > 0
        smooth: true
      }

      // 若无图片则显示名称浅色占位
      Text {
        anchors.centerIn: parent
        text: (root.portraitSource && root.portraitSource.toString().length > 0) ? "" : (root.name || "")
        color: "#666666"
        font.pixelSize: 16
        elide: Text.ElideRight
      }
    }

    // 名称
    Text {
      text: root.name || ""
      color: "#3b2f2f"
      font.pixelSize: 9
      font.bold: true
      width: parent.width
      horizontalAlignment: Text.AlignHCenter
      elide: Text.ElideRight
    }

    // 描述
    Text {
      text: root.description || ""
      color: "#463c35"
      font.pixelSize: 6
      wrapMode: Text.WordWrap
      width: parent.width
    }

    // 底部：攻防
    Item {
      width: parent.width
      height:10

      Row {
        spacing: 2
        anchors.horizontalCenter: parent.horizontalCenter
        anchors.verticalCenter: parent.verticalCenter

        Rectangle {
          width: 18
          height: 18
          radius: 6
          color: "#c53030"

          Text {
            anchors.centerIn: parent
            text: (root.atk === undefined || root.atk === null) ? 0 : root.atk
            color: "white"
            font.pixelSize: 20
            font.bold: true
          }
        }

        Rectangle {
          width: 18
          height: 18
          radius: 6
          color: "#2f855a"

          Text {
            anchors.centerIn: parent
            text: (root.hp === undefined || root.hp === null) ? 0 : root.hp
            color: "white"
            font.pixelSize: 20
            font.bold: true
          }
        }
      }
    }
  }
}